//
//  WanTableViewCell.m
//  MusicRunner
//
//  Created by Wan on 15/12/2.
//  Copyright © 2015年 WanWanSui. All rights reserved.
//

#import "THTableViewCell.h"

@implementation THTableViewCell
- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeColor" object:nil];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews {
    //    self.backgroundColor = [UIColor whiteColor];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor:) name:@"changeColor" object:nil];
    NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:@"night"];
    if ([string isEqualToString:@"yes"]) {
        self.backgroundColor = [UIColor blackColor];
    }
    else {
        self.backgroundColor = [UIColor whiteColor];
    }
    
}

- (void)changeColor:(NSNotification *)notification {
    NSString *string = [notification object];
    if ([string isEqualToString:@"yes"]) {
        self.backgroundColor = [UIColor blackColor];
        //        self.contentView.backgroundColor = [UIColor blackColor];
    } else {
        self.backgroundColor = [UIColor whiteColor];
    }
    //保存当前状态
    [[NSUserDefaults standardUserDefaults] setObject:string forKey:@"night"];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
